package com.hx.springboot1.dao;

import com.hx.springboot1.pojo.dto.StuDTO;
import com.hx.springboot1.pojo.entity.TabStudent;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Author: hx
 * Date: 2021-05-14 16/13
 * Description: Nothing else
 */
@Repository
@Mapper
public interface StuDao {
    @Select("select * from tab_student where user_id = #{id}")
    TabStudent selectByUserId(int id);
    @Select("select * from tab_student where stu_id = #{id}")
    TabStudent selectByStuId(int id);
    @Select("select stu_id,user_id,college_name,major_name,stu_name,stu_sex from tab_student a\n" +
            "join tab_college b on a.college_id=b.college_id\n" +
            "JOIN tab_major c on a.major_id=c.major_id")
    List<StuDTO> selectAllStu();
    @Select("select stu_id,user_id,college_name,major_name,stu_name,stu_sex from tab_student a\n" +
            "join tab_college b on a.college_id=b.college_id\n" +
            "JOIN tab_major c on a.major_id=c.major_id\n" +
            "where stu_name like #{name}")
    List<StuDTO> selectAllStuByName(String name);
    @Insert("insert into tab_student(user_id,college_id,major_id,stu_name,stu_sex)\n" +
            "values(#{userId},#{collegeId},#{majorId},#{stuName},#{stuSex})")
    int insertStu(int userId,int collegeId,int majorId,String stuName,String stuSex);
    @Delete("delete from tab_student where stu_id = #{sId}")
    int delStu(int sId);
    @Update("update tab_student set college_id=#{collegeId},major_id=#{majorId},stu_name=#{stuName},stu_sex=#{stuSex} where stu_id = #{stuId}")
    int updateStu(int stuId,int collegeId,int majorId,String stuName,String stuSex);
}
